import {
  GET_TOPIC_LIST, 
  GET_TOPIC_NEXT_LIST, 
  GET_TOPIC_INFO_CONTENT, 
  PLAY_TOPIC_NICE
} from '../constants/topicList'

const initialState = {
  page: 1,
  limit: 20,
  currentTabList: [],
  topicInfo: {},
  replyTopicInfo: [],
  playStatus: false
}

export default function topicListReducer(state = initialState, action){
  switch(action.type){
    case GET_TOPIC_LIST:
      return {...state, currentTabList: action.currentTabList, page: 1}
    case GET_TOPIC_NEXT_LIST:
      return {...state, currentTabList: state.currentTabList.concat(action.currentTabList), page: action.page}
    case GET_TOPIC_INFO_CONTENT:
      return {...state, topicInfo: {...action.getTopicInfoContent, replies: null}, replyTopicInfo: action.getTopicInfoContent.replies}
    case PLAY_TOPIC_NICE:
      return {...state, playStatus: !state.playStatus}
    default:
      return state
  }
}